package com.ali.gts.controller;

import com.ali.gts.domain.Emp;
import com.ali.gts.exception.GlobalException;
import com.ali.gts.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
public class ForwardAndRedirectController {

    Logger logger = LoggerFactory.getLogger(ForwardAndRedirectController.class);

    @Autowired
    private EmpService empService;


    @RequestMapping("/doForward")
    public ModelAndView doForward(int eid)  {

        ModelAndView modelAndView = new ModelAndView();
        Emp emp = empService.getEmpAndDep(eid);
        logger.info("emp的信息是{}",emp);
        modelAndView.addObject("msg",emp.getEmpName());
        //modelAndView.setViewName("forward:/WEB-INF/jsp/result.jsp");
        modelAndView.setViewName("forward:/hello.jsp");
        return modelAndView;
    }


    @RequestMapping("/doRedirect")
    public ModelAndView doRedirect(int eid)  {

        ModelAndView modelAndView = new ModelAndView();
        Emp emp = empService.getEmpAndDep(eid);
        logger.info("emp的信息是{}",emp);
        modelAndView.addObject("msg",emp.getEmpName());
        modelAndView.setViewName("redirect:/orther.jsp");
        return modelAndView;
    }
}
